/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.landmark;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author computer
 */
public class TaggingGUI extends Tagging{
    JFileChooser fc;

    /**
     * Creates new form RenameDirFileGUI
     */
    public TaggingGUI() {
        initComponents();
        fc = new JFileChooser();
        fc.setCurrentDirectory(new File("d:\\Talend\\TAG Building Fun\\"));
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fc.setMultiSelectionEnabled(false);
        modifyTagOutFilePanel.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtInputFolder = new javax.swing.JTextField();
        btnInputFolder = new javax.swing.JButton();
        btnChangeImageName = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jChkBoxTagOutChange = new javax.swing.JCheckBox();
        modifyTagOutFilePanel = new javax.swing.JPanel();
        txtTagOutFilePath = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        btnTagOutFilePath = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        txtTagOutDepFileFolder = new javax.swing.JTextField();
        btnTagOutFileDepFolder = new javax.swing.JButton();
        btnModtagOutFile = new javax.swing.JButton();

        setBackground(new java.awt.Color(0, 113, 187));
        setFont(new java.awt.Font("Cambria", 0, 11)); // NOI18N

        txtInputFolder.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N

        btnInputFolder.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        btnInputFolder.setText("...");
        btnInputFolder.setToolTipText("Select the folder with images");
        btnInputFolder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInputFolderActionPerformed(evt);
            }
        });

        btnChangeImageName.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        btnChangeImageName.setText("Modify Bank File");
        btnChangeImageName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChangeImageNameActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Bank Folder Path");

        jTextArea1.setBackground(new java.awt.Color(51, 51, 51));
        jTextArea1.setColumns(20);
        jTextArea1.setForeground(new java.awt.Color(255, 255, 51));
        jTextArea1.setRows(5);
        jTextArea1.setText("Select the folder in which the code\nwill search for the file named \nD:\\Talend\\TAG Building Fun\\BANKS\\UM_Tag_Bank_IN.csv\nand then adds the data present in the file \nD:\\Talend\\TAG Building Fun\\BANKS\\temp folder\nonce that is done have to the talend scrip[t again.");
        jScrollPane1.setViewportView(jTextArea1);

        jChkBoxTagOutChange.setBackground(new java.awt.Color(0, 113, 187));
        jChkBoxTagOutChange.setForeground(new java.awt.Color(255, 255, 255));
        jChkBoxTagOutChange.setText("Change Tag Out file");
        jChkBoxTagOutChange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jChkBoxTagOutChangeActionPerformed(evt);
            }
        });

        modifyTagOutFilePanel.setBackground(new java.awt.Color(0, 113, 187));
        modifyTagOutFilePanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        txtTagOutFilePath.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N

        jLabel3.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Tag Out File Path");

        btnTagOutFilePath.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        btnTagOutFilePath.setText("...");
        btnTagOutFilePath.setToolTipText("Select the Tag Out File");
        btnTagOutFilePath.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTagOutFilePathActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Tag Out File Dependent Files Folder Path");

        txtTagOutDepFileFolder.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N

        btnTagOutFileDepFolder.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        btnTagOutFileDepFolder.setText("...");
        btnTagOutFileDepFolder.setToolTipText("Select the Tag out dependent files");
        btnTagOutFileDepFolder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTagOutFileDepFolderActionPerformed(evt);
            }
        });

        btnModtagOutFile.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        btnModtagOutFile.setText("Modify Tag Out File");
        btnModtagOutFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModtagOutFileActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout modifyTagOutFilePanelLayout = new javax.swing.GroupLayout(modifyTagOutFilePanel);
        modifyTagOutFilePanel.setLayout(modifyTagOutFilePanelLayout);
        modifyTagOutFilePanelLayout.setHorizontalGroup(
            modifyTagOutFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(modifyTagOutFilePanelLayout.createSequentialGroup()
                .addGroup(modifyTagOutFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addGroup(modifyTagOutFilePanelLayout.createSequentialGroup()
                        .addComponent(txtTagOutFilePath, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnTagOutFilePath))
                    .addComponent(jLabel4)
                    .addGroup(modifyTagOutFilePanelLayout.createSequentialGroup()
                        .addComponent(txtTagOutDepFileFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnTagOutFileDepFolder))
                    .addComponent(btnModtagOutFile))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        modifyTagOutFilePanelLayout.setVerticalGroup(
            modifyTagOutFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(modifyTagOutFilePanelLayout.createSequentialGroup()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(modifyTagOutFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnTagOutFilePath)
                    .addComponent(txtTagOutFilePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(modifyTagOutFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnTagOutFileDepFolder)
                    .addComponent(txtTagOutDepFileFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnModtagOutFile)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtInputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnInputFolder))
                    .addComponent(jLabel2)
                    .addComponent(modifyTagOutFilePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnChangeImageName))
                    .addComponent(jChkBoxTagOutChange))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnInputFolder)
                    .addComponent(txtInputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jChkBoxTagOutChange)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(modifyTagOutFilePanel, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(52, 52, 52)
                        .addComponent(btnChangeImageName))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnChangeImageNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChangeImageNameActionPerformed
        if( txtInputFolder.getText().trim().equals("") ) {
            JOptionPane.showMessageDialog(Util.getHelperBean().getComponent(), "Please select a input folder", "Error", JOptionPane.OK_CANCEL_OPTION);            
        }else {  
            try{
                start();
            }catch( Exception e ) {
                JOptionPane.showMessageDialog(Util.getHelperBean().getComponent(), e.getLocalizedMessage());
                e.printStackTrace();
            }
        }        
        JOptionPane.showMessageDialog(Util.getHelperBean().getComponent(), "Done processing file");
    }//GEN-LAST:event_btnChangeImageNameActionPerformed

    private void btnInputFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInputFolderActionPerformed
        // TODO add your handling code here:
        //Handle open button action.
        if (evt.getSource() == btnInputFolder) {
            int returnVal = fc.showOpenDialog(Util.getHelperBean().getComponent());
            
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getCurrentDirectory();
                //System.out.println(fc.getSelectedFile().toString());
                this.strFolder = fc.getSelectedFile().toString();
                txtInputFolder.setText(fc.getSelectedFile().toString());
                //This is where a real application would open the file.
                //log.append("Opening: " + fc.getSelectedFile() + "." + newline);
            } else {
                JOptionPane.showMessageDialog(Util.getHelperBean().getComponent(), "Cancelled");
            }
            //log.setCaretPosition(log.getDocument().getLength());
 
        //Handle save button action.
        } 
    }//GEN-LAST:event_btnInputFolderActionPerformed

    private void btnTagOutFilePathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTagOutFilePathActionPerformed
        // TODO add your handling code here:
        //Handle open button action.
        if (evt.getSource() == btnTagOutFilePath) {
            fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

            int returnVal = fc.showOpenDialog(Util.getHelperBean().getComponent());
            
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                //System.out.println(fc.getSelectedFile().toString());
                this.strFolder = fc.getSelectedFile().toString();
                txtTagOutFilePath.setText(fc.getSelectedFile().toString());
                //This is where a real application would open the file.
                //log.append("Opening: " + fc.getSelectedFile() + "." + newline);
            } else {
                JOptionPane.showMessageDialog(Util.getHelperBean().getComponent(), "Cancelled");
            }
            //log.setCaretPosition(log.getDocument().getLength());
 
        //Handle save button action.
        }         // TODO add your handling code here:
    }//GEN-LAST:event_btnTagOutFilePathActionPerformed

    private void btnTagOutFileDepFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTagOutFileDepFolderActionPerformed
        // TODO add your handling code here:
        //Handle open button action.
        if (evt.getSource() == btnTagOutFileDepFolder) {
            fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            int returnVal = fc.showOpenDialog(Util.getHelperBean().getComponent());
            
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getCurrentDirectory();
                //System.out.println(fc.getSelectedFile().toString());
                this.strFolder = fc.getSelectedFile().toString();
                txtTagOutDepFileFolder.setText(fc.getSelectedFile().toString());
                //This is where a real application would open the file.
                //log.append("Opening: " + fc.getSelectedFile() + "." + newline);
            } else {
                JOptionPane.showMessageDialog(Util.getHelperBean().getComponent(), "Cancelled");
            }
            //log.setCaretPosition(log.getDocument().getLength());
 
        //Handle save button action.
        }         // TODO add your handling code here:
    }//GEN-LAST:event_btnTagOutFileDepFolderActionPerformed

    private void btnModtagOutFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModtagOutFileActionPerformed
        Util.getHelperBean().setFilePath(txtTagOutFilePath.getText());
        Util.getHelperBean().setFolderPath( txtTagOutDepFileFolder.getText());
        try{
//        this.changeTagFile();
        new TaggingSwingworker().execute();
        }catch( Exception e ) {
            JOptionPane.showMessageDialog(Util.getHelperBean().getComponent(), e.getStackTrace());
            e.printStackTrace();
        }
        
    }//GEN-LAST:event_btnModtagOutFileActionPerformed

    private void jChkBoxTagOutChangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jChkBoxTagOutChangeActionPerformed
        if( jChkBoxTagOutChange.isSelected() ) {
            modifyTagOutFilePanel.setVisible(true);
        } else {
            modifyTagOutFilePanel.setVisible(false);
        }
    }//GEN-LAST:event_jChkBoxTagOutChangeActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChangeImageName;
    private javax.swing.JButton btnInputFolder;
    private javax.swing.JButton btnModtagOutFile;
    private javax.swing.JButton btnTagOutFileDepFolder;
    private javax.swing.JButton btnTagOutFilePath;
    private javax.swing.JCheckBox jChkBoxTagOutChange;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JPanel modifyTagOutFilePanel;
    protected javax.swing.JTextField txtInputFolder;
    protected javax.swing.JTextField txtTagOutDepFileFolder;
    protected javax.swing.JTextField txtTagOutFilePath;
    // End of variables declaration//GEN-END:variables
}
